package junittestddcp;


import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.*;
import java.util.NoSuchElementException;


public class TestDoomsdayDevice {
	
	DoomsdayDevice myDevice;

	@Before
	public void setUp() throws Exception {
		myDevice = new DoomsdayDevice();
	}

	@After
	public void tearDown() throws Exception {
		myDevice = null;
	}
	
	
	
	/*********************** getReport() *********************/
	// tests the return values from getReport() method to check
	// that a report was generated.
	@Test
	public void testActionStatus(){		
		// start with a DoomsdayDevice and a configuration for it
		myDevice = new DoomsdayDevice();
		Configuration config = new Configuration();
		// declare the post action report
		PostActionReport postActionReport;
		
		// represent whether or not it was successful
		boolean resultActivation;
		
		// call to activate device method
		myDevice.activateDevice(config);
		
		// the post action report is this devices report after activation
		postActionReport = myDevice.getReport();
		
		// the successful attribute of this report for the activation
		resultActivation = postActionReport.successful;
		
		// asserting if results are same as expected
		assertTrue(resultActivation);
	}
	
	
	/******************* activateDevice() ********************/
	// Null input
	@Test(expected = NullPointerException.class)
	public void testActivateDeviceWithNullPointer(){
		myDevice.activateDevice(null);
	}
	
	// try to activated device with non-existent configuration
	@Test(expected=NoSuchElementException.class)
	public void testActivateDeviceNonExistentConfig(){
		Configuration nonExistant = new Configuration();
		myDevice.activateDevice(nonExistant);
	}
	
	@Test(expected=IllegalArgumentException.class)
	public void testActivateDeviceInvalidInput(){
		Configuration notAValidConfig =new Configuration();
		myDevice.activateDevice(notAValidConfig);
	}
	
	
}
